<?php
if (!$_GET['id']) {
    echo "Bad Request";
} else {
    $id = $_GET['id'];
//including header.php 
    include '../../include/header.php';
//including page.php (It is a class which contain functions)
    include '../../libraries/page.php';
    $page = new page();
    session_start();
    $userid = $_SESSION['userid'];

//checking the session
    if (!$_SESSION['username']) {
        header("location:../user/login.php");
    }

    if ($_GET['q'] == 'logout') {
        $page->user_logout();
        header("location:../user/login.php");
    }

//checking the data posted or not?
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
// for $_POST['submit'].  Remember, field names are determined by array keys!
        $result = $page->mysql_update_array("customers", $id, "customerid", $_POST);
        if ($result) {
            header("location:customers.php?status='1'");
        } else {
            $msg = $message[0];
        }
    }
    $customers = 'active';
    include '../../include/navbar.php';
    ?>

<div class="bread_crumb" style="margin-left: 2%">
    &laquo;  <a href="customers">Back</a>
  </div>
    <!--------------------------------------------------content----------------------------------->

    <!----------------------------------Display the result message of Update--------------------->
    <div  align="center"><?php echo $msg; ?></div>

    <!----------------------------------------------div for placing form here------------------------->
    <div style="width:290px;margin-left: auto;margin-right: auto;margin-top: 5%">
        <h3 style="color:#777;text-align: center">Update Customer</h3>
        <br />

        <!-----------------We are retrieving data from database table to display in the fields to update--------->
        <?
        //php code to get the data from groups table 
        $customer = mysql_query("select * from customers where customerid = $id");
        $customer_data = mysql_fetch_array($customer);

        ?>

        <?
        //date_default_timezone_set('Asia/Calcutta');
        //$date1 = date("Y-m-d H:i:s");
        ?>

        <!---------------------------------form------------------------------------------------>
        <form method="POST"  action="">
            <label>Customer</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="customer" value="<?= $customer_data['customer']; ?>"  required>
            <label>Address</label>
            <input class="input-xlarge" name="address" type="text" value="<?= $customer_data['address']; ?>">
            <label>Contact name</label>
            <input class="input-xlarge" name="contactname" type="text"  value="<?= $customer_data['contactname']; ?>">
            <label>Phone</label>
            <input class="input-xlarge"  type="tel" name="phone"  value="<?= $customer_data['phone']; ?>">
            <label>Tin</label>
            <input class="input-xlarge"  type="text" name="tin"  value="<?= $customer_data['tin']; ?>">
            <button class="btn btn-inverse" type="submit"   style="float:right; margin-right: 15px; margin-top: 20px;">Update</button> 
        </form>
    </div>

    <?php
//including footer.php
    include '../../include/footer.php';
    ?>
    <?php
//closing the first else conditon 
}
?>